package com.yzt.message.custom;

import android.os.Parcel;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yzt.zhuju.rongyun.IMMessageType;

import java.nio.charset.StandardCharsets;

import io.rong.common.ParcelUtils;
import io.rong.imlib.MessageTag;
import io.rong.imlib.model.MessageContent;

/**
 * 助手消息
 */
@MessageTag(value = IMMessageType.SERVER_NOTICE_MESSAGE,flag = MessageTag.NONE)
public class RXOfficeNoticeMessageContent extends MessageContent {

    private int type;
    private String data;

    @Override
    public byte[] encode() {
        return null;
    }

    public RXOfficeNoticeMessageContent() {
    }

    public RXOfficeNoticeMessageContent(byte[] data) {
        super(data);
        String jsonStr=null;
        try {
            jsonStr =new String(data, StandardCharsets.UTF_8);
            JSONObject object = JSON.parseObject(jsonStr);
            setType(object.getIntValue("type"));
            setData(object.getString("data"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        ParcelUtils.writeToParcel(dest,type);
        ParcelUtils.writeToParcel(dest, data);
    }

    public static final Creator<RXOfficeNoticeMessageContent> CREATOR = new Creator<RXOfficeNoticeMessageContent>() {

        @Override
        public RXOfficeNoticeMessageContent createFromParcel(Parcel source) {
            return new RXOfficeNoticeMessageContent(source);
        }

        @Override
        public RXOfficeNoticeMessageContent[] newArray(int size) {
            return new RXOfficeNoticeMessageContent[size];
        }
    };

    public RXOfficeNoticeMessageContent(Parcel parcel){
        type = ParcelUtils.readIntFromParcel(parcel);
        data = ParcelUtils.readFromParcel(parcel);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
}
